package com.lm.scau.dyb.fragment;

import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lm.scau.dyb.R;
import com.lm.scau.dyb.activity.base.BaseActivity;

/**
 * Function:
 * auth：liming on 2016/8/5 15:56
 * mail：liming@wxchina.com
 */
public class TitleFragment extends Fragment {

    private RelativeLayout backLayout;
    private ImageView imageViewAdd;
    private TextView titleText;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.title_bar_layout, container, false);
        backLayout = (RelativeLayout) view.findViewById(R.id.back_layout);
        imageViewAdd = (ImageView) view.findViewById(R.id.add_image_view);
        titleText = (TextView) view.findViewById(R.id.text_view_title);
        backLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((BaseActivity)getActivity()).finish();
            }
        });
        return view;
    }


    private void setBackLayoutVisibility(boolean hide) {
        if (hide) {
            backLayout.setVisibility(View.GONE);
        } else {
            backLayout.setVisibility(View.VISIBLE);
        }
    }

    private void setImageViewAddVisibility(boolean hide) {
        if (hide) {
            imageViewAdd.setVisibility(View.GONE);
        } else {
            imageViewAdd.setVisibility(View.VISIBLE);
        }
    }

    public void setTitleText(String title) {
        titleText.setText(title);
    }

    /**
     * 初始化标题栏
     *
     * @param backHide    是否隐藏返回键
     * @param addViewHide 是否隐藏add
     * @param title       标题文字
     */
    public void initTitle(boolean backHide, boolean addViewHide, String title) {
        setBackLayoutVisibility(backHide);
        setImageViewAddVisibility(addViewHide);
        setTitleText(title);
    }
}
